package indi.kane.simpleproject.controller;

import indi.kane.simpleproject.entity.Profession;
import indi.kane.simpleproject.service.impl.ProfessionService;
import indi.kane.simpleproject.vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @ClassName: ProfessionController
 * @Author: kane
 * @Date: 2019-11-05 6:55 下午
 * @Description:
 */
@RestController
@RequestMapping("profession")
public class ProfessionController {
    @Autowired
    private ProfessionService professionService;

    @RequestMapping(value = "insert", method = RequestMethod.POST)
    public ResultVo insert(@RequestBody Profession profession){
        try {
            int result = professionService.insertSelective(profession);
            if(result > 0){
                return ResultVo.success("ok");
            }
            return ResultVo.failed("failed");
        }
        catch (Exception ex){
            return ResultVo.failed_exception(ex.getMessage());
        }
    }

    @RequestMapping("all")
    public ResultVo all(){
        try {
            List<Profession> professions = professionService.loadAll();
            if(professions != null){
                return ResultVo.success(professions);
            }
            return ResultVo.failed("failed");
        }
        catch (Exception ex){
            return ResultVo.failed_exception(ex.toString());
        }
    }
}